﻿import 'package:flutter/widgets.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:get/get.dart';

class BuilderFormsState {
  final GlobalKey<FormBuilderState> formKey = GlobalKey<FormBuilderState>();

  final RxnString regionLabel = RxnString();

  final List<String> defaultRegion = const ['浙江省', '杭州市', '西湖区'];

  final Map<String, Map<String, List<String>>> regionOptions = const {
    '浙江省': {
      '杭州市': ['西湖区', '余杭区', '萧山区'],
      '宁波市': ['江东区', '北仑区', '奉化市'],
    },
    '广东省': {
      '深圳市': ['南山区', '罗湖区', '福田区'],
      '广州市': ['天河区', '越秀区', '海珠区'],
    },
    '北京市': {
      '北京市': ['朝阳区', '海淀区', '东城区'],
    },
  };

  final List<FormBuilderFieldOption> radioOptions = [
  FormBuilderFieldOption(value: 1, child: Text('线上商城')),
  FormBuilderFieldOption(value: 2, child: Text('线下门店')),
  // FormBuilderFieldOption(value: 3, child: Text('渠道分销')),
  ];

  List<String> resolveInitialRegion(String? value) {
    final current = List<String>.from(defaultRegion);
    final source = value ?? regionLabel.value;
    if (source == null || source.isEmpty) {
      return current;
    }

    final parts = source.split(' / ');
    for (var i = 0; i < parts.length && i < current.length; i++) {
      current[i] = parts[i];
    }
    return current;
  }

  void updateRegionLabel(String? value) {
    regionLabel.value = value;
  }
}
